#!/usr/bin/python3

import sys
friend_dict = {}
for l in sys.stdin:
    l = l.strip()
    pair, friend = l.split()
    if pair not in friend_dict:
        friend_dict[pair] = friend
    else:
        friend_dict[pair] += friend

for key, value in friend_dict.items():
    print(key, value)
